package android.app.gfestival.adapter;

import java.util.List;

import android.app.gfestival.R;
import android.app.gfestival.soap.EventDate;
import android.app.gfestival.utils.DateTimeUtil;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ProgramFistAdapter extends BaseAdapter{
		
		private List<EventDate> list;
		private Context context;

		public ProgramFistAdapter(Context context, List<EventDate> dayEvents){
			this.list = dayEvents;
			this.context = context;
		}
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parentView) {
			// TODO Auto-generated method stub
			Holder holder = null;
			if(convertView == null){
				LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				convertView = inflater.inflate(R.layout.program_fist_item, null);
				holder = new Holder();
				holder.textView = (TextView) convertView.findViewById(R.id.textview_pro_fist);
				convertView.setTag(holder);
			}else{
				holder = (Holder) convertView.getTag();
			}
			String day = DateTimeUtil.convertDate(list.get(position).event_day,"EEEE dd - MMM yyyy").replace("-", "of");
			holder.textView.setText(convertDay(day));
			return convertView;
		}
		
		private class Holder{
			TextView textView;
		}
		private String convertDay(String day){
			if(day.contains("Monday")){
				day = day.replace("Monday", context.getString(R.string.monday));
			}else if(day.contains("Tuesday")){
				day = day.replace("Tuesday", context.getString(R.string.tuesday));
			}else if(day.contains("Wednesday")){
				day = day.replace("Wednesday", context.getString(R.string.wednesday));
			}else if(day.contains("Thursday")){
				day = day.replace("Thursday", context.getString(R.string.thursday));
			}else if(day.contains("Friday")){
				day = day.replace("Friday", context.getString(R.string.friday));
			}else if(day.contains("Saturday")){
				day = day.replace("Saturday", context.getString(R.string.saturday));
			}else if(day.contains("Sunday")){
				day = day.replace("Sunday", context.getString(R.string.sunday));
			}
			return day;
		}
		
	}